Skip to content

Dark Mode issues Fixes #13474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Dark Mode issues Fixes #13474

wants to merge 4 commits into from

Conversation

memoarfaa
Copy link

@memoarfaa memoarfaa commented May 17, 2025

Fix Dark Mode issues

Fixes #12027
Fixes #12992
Fixes #12991
Fixes #12582
Fixes #11941
Fixes #11932

Microsoft Reviewers: Open in CodeFlow

@memoarfaa memoarfaa requested a review from a team as a code owner May 17, 2025 20:53
@github-actions github-actions bot added the area-DarkMode Issues relating to Dark Mode feature label May 17, 2025
Copy link

codecov bot commented May 18, 2025

Codecov Report

Attention: Patch coverage is 22.41379% with 45 lines in your changes missing coverage. Please review.

Project coverage is 76.59997%. Comparing base (716bc12) to head (fcdac7c).

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main      #13474         +/-   ##
===================================================
+ Coverage   76.59823%   76.59997%   +0.00173%     
===================================================
  Files           3230        3230                 
  Lines         639097      639153         +56     
  Branches       47289       47297          +8     
===================================================
+ Hits          489537      489591         +54     
+ Misses        145992      145984          -8     
- Partials        3568        3578         +10     
Flag Coverage Δ
Debug 76.59997% <22.41379%> (+0.00173%) ⬆️
integration 18.79560% <18.96552%> (+0.01347%) ⬆️
production 51.00769% <22.41379%> (+0.00887%) ⬆️
test 97.40411% <ø> (ø)
unit 48.41589% <22.41379%> (+0.02962%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@KlausLoeffelmann
Copy link
Member

Hey @memoarfaa,

thanks for this PR, but let's try to coordinate the efforts here, so we're not doing redundant work.
Can you explain, which parts of the your PR is addressing which Issues, and point out the background a bit?

We'll be addressing for Preview 5 (maybe early 6) the PRs which I did, since they had been planned and championed. We only have Monday 19th to complete testing, reviews and merge them, so the Preview 5 ship for any pivoting in approaches has sailed.

For Preview 6, I'd love to re-discuss approaches, though, so, let's keep the discussion rolling for improvements for the Preview 6 time frame!

PS:
If you have a good, feasible idea or approach, which we could take on (really!) short notice for the background-coloring of a read-only TextBox or RTF TextBox in DarkMode, without changing the default color (which would be too invasive), that would be really cool!!

@memoarfaa
Copy link
Author

memoarfaa commented May 19, 2025

Hey @memoarfaa,

Hey @KlausLoeffelmann

thanks for this PR, but let's try to coordinate the efforts here, so we're not doing redundant work. Can you explain, which parts of the your PR is addressing which Issues, and point out the background a bit?

Ok I will do

We'll be addressing for Preview 5 (maybe early 6) the PRs which I did, since they had been planned and championed. We only have Monday 19th to complete testing, reviews and merge them, so the Preview 5 ship for any pivoting in approaches has sailed.

I understand that for Preview 5, only the already planned/championed PRs can be considered, and my changes won’t be merged at this stage.

For Preview 6, I'd love to re-discuss approaches, though, so, let's keep the discussion rolling for improvements for the Preview 6 time frame!

For Preview 6, I’m happy to continue iterating on these improvements and would appreciate any feedback or direction from the team on priorities or preferred approaches.

PS: If you have a good, feasible idea or approach, which we could take on (really!) short notice for the background-coloring of a read-only TextBox or RTF TextBox in DarkMode, without changing the default color (which would be too invasive), that would be really cool!!

About Read-Only TextBox Background Coloring in Dark Mode

I don't understand what you mean by

"without changing the default color"

If you mean the Win32 default theme Color the answer is no because it handled by WM_CTLCOLOR XXXX
if you mean the WinForms repo defaults BackColor and ForColor I'm using the same approach in Win32 WM_CTLCOLOR XXXX
explanation,
in TextBoxBase class

internal override HBRUSH InitializeDCForWmCtlColor(HDC dc, MessageId msg)
   {
#pragma warning disable WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
       bool isReadOnly = (PInvokeCore.GetWindowLong(this, WINDOW_LONG_PTR_INDEX.GWL_STYLE) & PInvoke.ES_READONLY) != 0;
       if (Application.IsDarkModeEnabled && isReadOnly)
       {
           switch (msg)
           {
               // In dark mode, a disabled edit control will paint the background and forground with light colors
               case PInvokeCore.WM_CTLCOLOREDIT:
                   PInvokeCore.SetBkColor(dc, 0x1A1A1A);
                   PInvokeCore.SetTextColor(dc, 0xffffff);
                   return PInvokeCore.CreateSolidBrush(0x1A1A1A);
               case PInvokeCore.WM_CTLCOLORSTATIC:
                   PInvokeCore.SetBkMode(dc, BACKGROUND_MODE.TRANSPARENT);
                   PInvokeCore.SetTextColor(dc, 0x6A6A6A);
                   return PInvokeCore.CreateSolidBrush(0x232323);
               default:
                   return base.InitializeDCForWmCtlColor(dc, msg);
           }
       }

#pragma warning restore WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
    else
       {
           if (msg == PInvokeCore.WM_CTLCOLORSTATIC && !ShouldSerializeBackColor())
           {
               // Let the Win32 Edit control handle background colors itself.
               // This is necessary because a disabled edit control will display a different
               // BackColor than when enabled.
               return default;

           }
           else
           {
               return base.InitializeDCForWmCtlColor(dc, msg);
           }
       }
   }

in RichTextBox Class

    private bool InternalSetForeColor(Color value)
    {

        CHARFORMAT2W cf = GetCharFormat(false);
        if ((cf.dwMask & CFM_MASK.CFM_COLOR) != 0
            && ColorTranslator.ToWin32(value) == cf.crTextColor)
        {
            return true;
        }

        cf.dwMask = CFM_MASK.CFM_COLOR;
        cf.dwEffects = 0;
#pragma warning disable WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
        cf.crTextColor = Application.IsDarkModeEnabled && ReadOnly
            ? 0x6A6A6A
            : ColorTranslator.ToWin32(value);
#pragma warning restore WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
        return SetCharFormat(PInvoke.SCF_ALL, cf);
    }

Recording.2025-05-19.095641.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment